package com.example.controller;


import com.example.Service.WeatherService;
import com.example.entity.RestBean;

import com.example.entity.vo.redponse.WeatherVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 作者:xuSen
 * 日期2025/4/27 8:35
 */
@RestController
@RequestMapping("/api/forum")
public class ForumController {
    @Resource
    private WeatherService weatherService;
    @GetMapping("/weather")
    public RestBean<WeatherVO> weather(Double longitude, Double latitude) {
        if (longitude == null || latitude == null) {
            return RestBean.failure(400, "经度和纬度参数不能为空");
        }
        WeatherVO weatherVO = weatherService.fetchWeather(longitude, latitude);
        if(weatherVO==null) return RestBean.failure(500,"获取天气信息失败");
        return RestBean.success(weatherVO);
    }
}
